package puj.news.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import puj.news.dto.Mensaje;

import com.google.gson.Gson;

/**
 * Servlet implementation class LikeUser
 */
@WebServlet("/likeuser")
public class LikeUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LikeUser() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String idnoticia = " ";
		String idusuario = " ";
		String like = " ";

		try {
			idnoticia = (String) request.getParameter("idnoticia");
			idusuario = (String) request.getParameter("idusuario");
			like = (String) request.getParameter("like");
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		response.setCharacterEncoding("UTF-8");

		response.setContentType("application/json");

		Gson gson = new Gson();

		Mensaje mensaje = new Mensaje();

		System.out.println("idnoticia: "+idnoticia+", idusuario: "+idusuario+", like: "+like);
		mensaje.setId(idnoticia);
		if (like.equals("img/like2.png")) {
			mensaje.setMensaje("img/like1.png");
		}
		else{
			mensaje.setMensaje("img/like2.png");
		}

		String json = gson.toJson(mensaje);

		response.getOutputStream().println(json);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
